# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms_hi.dm.sqs_report.complaint.dm_waybill_customer_complaint_detail_new_hi import \
    jms_hi_dm__dm_waybill_customer_complaint_detail_new_hi
from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms_hi.dwd.tab.dwd_tab_barscan_sitearrival_base_hi import jms_dwd__dwd_tab_barscan_sitearrival_base_hi
from jms_hi.dm.sqs_report.check_dwd_yl_oms_oms_waybill_last_hour_status import \
    jms_dwd__check_dwd_yl_oms_oms_waybill_last_hour_status

jms_hi_dm__dm_waybill_customer_complaint_network_agg_new_hi = SparkSqlOperator(
    task_id='jms_hi_dm__dm_waybill_customer_complaint_network_agg_new_hi',
    email=['shenjiaming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    pool_slots=5,
    master='yarn',
    name='jms_hi_dm__dm_waybill_customer_complaint_network_agg_new_hi_{{ execution_date | cst_ds_nodash }}',
    sql='jms_hi/dm/sqs_report/complaint/dm_waybill_customer_complaint_network_agg_new_hi/execute.hql',
    driver_memory='2G' , 
    executor_memory='3G' , 
    executor_cores=2 , 
    num_executors=5 , 
    yarn_queue='pro',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 6 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G' , 
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 5000,
              'hive.exec.max.dynamic.partitions': 30000,
              },
    execution_timeout=timedelta(minutes=30),

)

jms_hi_dm__dm_waybill_customer_complaint_network_agg_new_hi << [
    jms_hi_dm__dm_waybill_customer_complaint_detail_new_hi
    , jms_dim__dim_network_whole_massage
    , jms_dwd__dwd_tab_barscan_sitearrival_base_hi
    , jms_dwd__check_dwd_yl_oms_oms_waybill_last_hour_status
]
